home *** CD-ROM | disk | FTP | other *** search
- #define NUM_LINES 50
- #define NIL_POINTER 0L
- #define MOVE_TO_FRONT -1L
- #define REMOVE_ALL_EVENTS 0
- #define NIL_STRING "\P"
- #define NIL_TITLE NIL_STRING
- #define VISIBLE TRUE
- #define NO_GO_AWAY FALSE
- #define NIL_REF_CON NIL_POINTER
-
- WindowPtr gLineWindow;
- Rect gLines[NUM_LINES];
- int gDeltaTop=3, gDeltaBottom=4;
- int gDeltaLeft=2, gDeltaRight=6;
- int gOldMBarHeight;
-
- main()
- {
- ToolBoxInit();
- WindowInit();
- LinesInit();
- MainLoop();
- }
-
- ToolBoxInit()
- {
- InitGraf(&thePort);
- InitFonts();
- FlushEvents(everyEvent,REMOVE_ALL_EVENTS);
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(NIL_POINTER);
- InitCursor();
- }
-
- WindowInit()
- {
- Rect totalRect, mBarRect;
- RgnHandle mBarRgn;
-
- gOldMBarHeight = MBarHeight;
- MBarHeight=0;
- gLineWindow = NewWindow(NIL_POINTER, &(screenBits.bounds),
- NIL_TITLE, VISIBLE, plainDBox, MOVE_TO_FRONT, NO_GO_AWAY,
- NIL_REF_CON);
-
- SetRect( &mBarRect, screenBits.bounds.left, screenBits.bounds.top,
- screenBits.bounds.right, screenBits.bounds.top+gOldMBarHeight);
- mBarRgn = NewRgn();
- RectRgn(mBarRgn, &mBarRect);
- UnionRgn(gLineWindow->visRgn, mBarRgn, gLineWindow->visRgn);
- DisposeRgn(mBarRgn);
-
- SetPort(gLineWindow);
- FillRect(&(gLineWindow->portRect), black);
- PenMode(patXor);
- }
-
- LinesInit()
- {
- int i;
-
- HideCursor();
- GetDateTime(&randSeed);
- RandomRect(&(gLines[0]), gLineWindow);
- DrawLine(0);
- for(i=1; i<NUM_LINES; i++)
- {
- gLines[i] =gLines[i-1];
- RecalcLine(i);
- DrawLine(i);
- }
- }
-
- MainLoop()
- {
- int i;
-
- while(!Button())
- {
- DrawLine(NUM_LINES-1);
- for(i=NUM_LINES-1; i>0;i--)
- gLines[i] = gLines[i-1];
- RecalcLine(0);
- DrawLine(0);
- }
- MBarHeight = gOldMBarHeight;
- }
-
- RandomRect (myRectPtr, boundingWindow)
- Rect *myRectPtr;
- WindowPtr boundingWindow;
- {
- myRectPtr->left = Randomize(boundingWindow->portRect.right
- - boundingWindow->portRect.left);
- myRectPtr->right = Randomize(boundingWindow->portRect.right
- - boundingWindow->portRect.left);
- myRectPtr->top = Randomize(boundingWindow->portRect.bottom
- - boundingWindow->portRect.top);
- myRectPtr->bottom = Randomize(boundingWindow->portRect.bottom
- - boundingWindow->portRect.top);
- }
-
- Randomize(range)
- int range;
- {
- long rawResult;
-
- rawResult= Random();
- if(rawResult<0)rawResult*= -1;
- return((rawResult*range)/32768);
- }
-
- RecalcLine(i)
- int i;
- {
- gLines[i].top += gDeltaTop;
- if(( gLines[i].top< gLineWindow->portRect.top) ||
- (gLines[i].top> gLineWindow->portRect.bottom))
- {
- gDeltaTop *= -1;
- gLines[i].top += 2*gDeltaTop;
- }
-
- gLines[i].bottom += gDeltaBottom;
- if(( gLines[i].bottom< gLineWindow->portRect.top) ||
- (gLines[i].bottom> gLineWindow->portRect.bottom))
- {
- gDeltaBottom *= -1;
- gLines[i].bottom += 2*gDeltaBottom;
- }
-
- gLines[i].left += gDeltaLeft;
- if(( gLines[i].left< gLineWindow->portRect.left) ||
- (gLines[i].left> gLineWindow->portRect.right))
- {
- gDeltaLeft *= -1;
- gLines[i].left += 2*gDeltaLeft;
- }
-
- gLines[i].right += gDeltaRight;
- if(( gLines[i].right< gLineWindow->portRect.left) ||
- (gLines[i].right> gLineWindow->portRect.right))
- {
- gDeltaRight *= -1;
- gLines[i].right += 2*gDeltaRight;
- }
- }
-
- DrawLine(i)
- int i;
- {
- MoveTo(gLines[i].left, gLines[i].top);
- LineTo(gLines[i].right, gLines[i].bottom);
- }
-
-
-
-
-